package njust.csc.aeapi.service

import njust.csc.aeapi.dao.SdkFilterRepository
import njust.csc.aeapi.dao.UrlFilterRepository
import njust.csc.aeapi.entity.SdkFilter
import njust.csc.aeapi.entity.UrlFilter
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * @Author ZhouHang
 * @Date 24/8/12 周一
 */
@Service
class SdkFilterService @Autowired constructor(
    private val sdkFilterRepository: SdkFilterRepository,
) {
    fun findAll(): List<SdkFilter> {
        return sdkFilterRepository.findAll()
    }

    // TODO 这里应当返回新增或更新记录的 id
    fun saveOrUpdate(sdkFilter: SdkFilter) {
        sdkFilterRepository.save(sdkFilter)
    }

    fun delete(id: Int) {
        sdkFilterRepository.deleteById(id)
    }
}

@Service
class UrlFilterService @Autowired constructor(
    private val urlFilterRepository: UrlFilterRepository
) {
    fun findAll(): List<UrlFilter> {
        return urlFilterRepository.findAll()
    }

    fun saveOrUpdate(urlFilter: UrlFilter) {
        urlFilterRepository.save(urlFilter)
    }

    fun delete(id: Int) {
        urlFilterRepository.deleteById(id)
    }
}
